﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class BattleAttackBtn : MonoBehaviour,IPointerDownHandler,IPointerUpHandler
{
    
    public float stayJudgeTime = 0.15f;

    private float m_ButtonDownTime;

    public Action onClick;
    
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void OnPointerDown(PointerEventData eventData)
    {
        m_ButtonDownTime = Time.realtimeSinceStartup;
    }
    
    public void OnPointerUp(PointerEventData eventData)
    {
        if (Time.realtimeSinceStartup - m_ButtonDownTime < stayJudgeTime)
        {
            if (onClick != null)
            {
                GameDebug.LogShowy($"On Pointer up  attack launch");
                Invoke(nameof(InvokeOnClick),0.016f);
            }
            else
            {
                GameDebug.LogError("onClick == null");
            }
        }
    }

    void InvokeOnClick()
    {
        onClick.Invoke();
    }
}